Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

feat: use math.prod instead of a for loop#27

Merged
morgante merged 3 commits intogetgrit:mainfrom
vlopezferrando:math-prod-instead-of-for
Sep 23, 2023
Merged

feat: use math.prod instead of a for loop#27
morgante merged 3 commits intogetgrit:mainfrom
vlopezferrando:math-prod-instead-of-for

Conversation

@vlopezferrando
Copy link
Contributor

This PR depends on #25.

This pattern transforms a loop that computes the product of a list of numbers into a call to math.prod (introduced in Python 3.8).

@vlopezferrando
Copy link
Contributor Author

@morgante One question: I have seen that when using the pattern of matching an after and deleting it with => ., a blank line is left. Is there a way to remove this line too?

@morgante
Copy link
Contributor

@morgante One question: I have seen that when using the pattern of matching an after and deleting it with => ., a blank line is left. Is there a way to remove this line too?

Not easily. We mostly try to leave formatting changes like that out of scope and rely on formatters to clean things up after the Grit migration.

@vlopezferrando
Copy link
Contributor Author

Great, makes sense.

}
}

`$for` where {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will match anything and then restrict it, which ends up being much worse for performance. It's better to hoist the for_statement up as the main thing we're matching against.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@morgante morgante merged commit 492fe45 into getgrit:main Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants